package com.lili.collection.core.fields.support;

import cn.hutool.core.util.StrUtil;

import java.time.ZonedDateTime;
import java.time.format.DateTimeParseException;

public class ZonedDateTimeTypeSupport extends TypeSupport<ZonedDateTime> {
    @Override
    public ZonedDateTime convert(Object value) {
        if (value instanceof ZonedDateTime) {
            return (ZonedDateTime) value;
        }

        try {
            Utils.checkArgument(
                    value instanceof String,
                    StrUtil.format("值：{}不支持转换为类型：{}，", value.getClass().getSimpleName(), value)
            );
            return Utils.parseZoned((String) value);
        } catch (DateTimeParseException ex) {
            throw new TypeSupportConversionException(value.getClass().getSimpleName(), value);
        }
    }

    @Override
    public Object create(Object value) {
        return clone(value);
    }

    @Override
    public Object get(Object value) {
        return clone(value);
    }

    @Override
    public Object clone(Object value) {
        return value;
    }

}
